package com.team2.outpatient_sys.web.applet;

import com.team2.outpatient_sys.pojo.CaseHistory;
import com.team2.outpatient_sys.pojo.Result;
import com.team2.outpatient_sys.service.CaseHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/applet/case")
public class CaseHistoryController {
    @Autowired
    private CaseHistoryService caseHistoryService;

    /**
     * 处理根据病人id查询病人所有病历信息请求的Controller方法
     * @param patientId 病人id
     * @return 查询到的病人病历信息的集合
     */
    @GetMapping("/pid/{patientId}")
    public Result getByPatientId(@PathVariable Integer patientId) {
        List<CaseHistory> caseHistoryList = caseHistoryService.searchCaseHistory(patientId);
        Result result = new Result();
        if (caseHistoryList == null) {
            result.setCode(500);
            result.setMsg("根据病人id查询病历信息时发生异常");
        } else {
            result.setCode(200);
            result.setMsg("根据病人id查询病历信息成功");
            result.setData(caseHistoryList);
        }
        return result;
    }
}
